---
title: "Backlash or Progressive Mobilization? Voter Reactions to Perceived Trajectories
  of Women's Representation"
subtitle: "Replication File"
author: "Magdalena Breyer"
date: "Last compiled: `r Sys.Date()`"
output: 
    html_document:
        toc: true
        code_folding: hide
---

```{r setup, include=TRUE}
knitr::opts_chunk$set(echo = TRUE, warning = F, message = F)

# packages
if (!require("pacman")) install.packages("pacman") 

pacman::p_load(tidyverse, # CRAN v2.0.0
               broom, # CRAN v1.0.5
               ggeffects, # CRAN v1.2.3 
               modelsummary, # CRAN v1.4.1
               gridExtra, # CRAN v2.3
               estimatr, # CRAN v1.0.0
               readxl, # CRAN v1.4.3
               rvest, # CRAN v1.0.3
               viridis, # CRAN v0.6.4 
               geomtextpath, # CRAN 0.1.1
               kableExtra, # CRAN v1.3.4
               rigr # CRAN v1.0.4
)
theme_set(theme_bw())

# paths to edit
## for loading data
data_path <- "../data/"

# for exporting figures
figures_path <- "../plots/results/replication"

```

# Data 
```{r}

df <- read_csv(paste0(data_path, "df_replication_breyer.csv"))

# exclude nonbinary respondents for analyses by men versus women
df_mf <- df %>% 
  filter(gender != "nonbinary")

```

# Functions for plots

```{r}
# ggplot settings for output from ggpredict function from ggeffects package
## Default settings: 0.834 Confidence Intervals

## Function to plot 2-way interaction effects/CATE as predicted values in facets

plotcate <- function(model, terms, cilvl = 0.834, 
                     scaleyname = model[["terms"]][[2]],
                     subtitle = NULL, ...
){
  ggpredict(model, terms, cilvl) %>% 
    ggplot(aes(as.numeric(x), predicted)) + 
    geom_point(size=2)+ 
    geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15)+
    facet_wrap(~group)+
    scale_x_continuous(name = NULL, breaks = c(1,2,3), labels = c("Control", "Women\nstagnate", "Women\nrise")) +
    scale_y_continuous(name = scaleyname, ...) +
    labs(subtitle = subtitle) +
    theme(legend.position = "bottom")+
    theme(panel.grid.minor = element_blank(),
          panel.grid.major.x = element_blank()
    )
}

## Function to plot 3-way interaction effects (covariate with 2 levels)

plotcate3 <- function(model, terms, cilvl = 0.834, 
                        scaleyname = model[["terms"]][[2]],
                        subtitle = NULL, ...
){
  ggpredict(model, terms, cilvl) %>%
    ggplot(aes(as.numeric(x), predicted, color = group)) + 
    geom_point(position = position_dodge(.4), size=2)+ 
    geom_errorbar(aes(ymin = conf.low, ymax = conf.high), position = position_dodge(.4), width = .15)+
    scale_x_continuous(name = NULL, breaks = c(1,2,3), labels = c("Control", "Women\nstagnate", "Women\nrise")) +
    scale_y_continuous(name = scaleyname) +
    scale_color_manual(values = c("grey65", "black"),
                       na.translate = F, name = NULL) +
    facet_wrap(~facet)+
    labs(subtitle = subtitle) +
    theme(legend.position = "bottom")+
    theme(panel.grid.minor = element_blank(),
          panel.grid.major.x = element_blank()
    )
}

## Function to plot 3-way interaction effects (covariate with 3 levels)

plotcate3col <- function(model, terms, cilvl = 0.834, 
                      scaleyname = model[["terms"]][[2]],
                      subtitle = NULL, ...
){
  ggpredict(model, terms, cilvl) %>%
    ggplot(aes(as.numeric(x), predicted, color = group)) + 
    geom_point(position = position_dodge(.4), size=2)+ 
    geom_errorbar(aes(ymin = conf.low, ymax = conf.high), position = position_dodge(.4), width = .15)+
    scale_x_continuous(name = NULL, breaks = c(1,2,3), labels = c("Control", "Women\nstagnate", "Women\nrise")) +
    scale_y_continuous(name = scaleyname) +
    scale_color_manual(values = c("grey80", "grey50", "black"),
                       na.translate = F, name = NULL) +
    facet_wrap(~facet)+
    labs(subtitle = subtitle) +
    theme(legend.position = "bottom")+
    theme(panel.grid.minor = element_blank(),
          panel.grid.major.x = element_blank()
    )
}
```


# Main Text results

## Figure 2 

Subjective social status, present and trajectory

```{r, fig.height = 7}
# Subjective social status, present and trajectory

## HC2 is default for lm_robust
model4a <- lm_robust(sssn ~ treatment, data = df_mf)
model6a <- lm_robust(sssn ~ treatment * gender, data = df_mf)

sss <- plotcate(model6a, c("treatment", "gender"), 0.834,
         "Present SSS", "Present SSS")

model4b <- lm_robust(sss_develop ~ treatment, data = df_mf)
model6b <- lm_robust(sss_develop ~ treatment * gender, data = df_mf)

sss_t <- plotcate(model6b, c("treatment", "gender"), 0.834, 
                  "SSS trajectory", "SSS trajectory (future minus past SSS)")

# combine plots
plots_sss <- arrangeGrob(sss, sss_t, 
                         nrow = 2, heights = unit(c(8.5,8.5), c("cm"))
)

grid.arrange(plots_sss)

ggsave(file = "figure2.pdf", path = figures_path, plot = plots_sss,
       width = 15, height = 17, units = "cm")

```

## Figure 3


```{r, fig.height = 3.5}
# Political centrality
model7 <- lm_robust(pol_depr_mean ~ treatment, data = df_mf)
model9 <- lm_robust(pol_depr_mean ~ treatment * gender, data = df_mf)

plotcate(model9, c("treatment", "gender"), scaleyname = "Political centrality")

ggsave(file = "figure3.pdf", path = figures_path,
       width = 15, height = 8.5, units = "cm")
```

## Figure 4

```{r, fig.height = 3.5}
# Prioritize support for boys
ms5 <- lm_robust(boyssupport ~ treatment * gender, data = df_mf)

plotcate(ms5, c("treatment", "gender"), scaleyname = "Primarily support for boys needed")

ggsave(file = "figure4.pdf", path = figures_path,
       width = 15, height = 8.5, units = "cm")

```

## Figure 5

```{r, fig.height = 7}
# Propensity to vote AfD/Greens
model10 <- lm_robust(ptv_afd ~ treatment, data = df_mf)
model11 <- lm_robust(ptv_afd ~ treatment * gender, data = df_mf)

pafd <- plotcate(model11, terms = c("treatment", "gender"),
                 scaleyname = "PtV AfD",
                 subtitle = "Radical Right"
                 )

model12 <- lm_robust(ptv_gruene ~ treatment, data = df_mf)
model13 <- lm_robust(ptv_gruene ~ treatment * gender, data = df_mf)

pgru <- plotcate(model13, terms = c("treatment", "gender"),
                 scaleyname = "PtV Greens",
                 subtitle = "Greens"
                 )

# combine plots
plots_ptv <- arrangeGrob(pafd, pgru, 
                         nrow = 2, heights = unit(c(8.5, 8.5), c("cm"))
)

grid.arrange(plots_ptv)

ggsave(file = "figure5.pdf", path = figures_path, plot = plots_ptv,
       width = 15, height = 17, units = "cm")

```


## Figure 6

```{r, fig.height = 3.5}
# Green PtV by gender and feminist attitude
model_f13a <- lm_robust(ptv_gruene ~ treatment * fem_group2, data = df)
model_fg13a <- lm_robust(ptv_gruene ~ treatment * gender * fem_group2, data = df_mf)

plotcate3(model_fg13a, c("treatment",  "fem_group2", "gender"),
          scaleyname = "PtV Greens")

ggsave(file = "figure6.pdf", path = figures_path,
       width = 15, height = 9.5, units = "cm")
```


# Online Appendix

## Appendix A

### Figure A1

```{r, fig.height = 7}
# IPU historical 1948-2018

# Source: https://data.ipu.org/historical-women

ipu <- read_xlsx(paste0(data_path,"women_in_parliament-historical_database-1945_to_2018.xlsx")) %>%
  filter(`Chamber Type` %in% c("Lower", "Single")) %>% 
  rename(share_womenc = "% Of Women in Chamber") %>% 
  mutate(share_women = as.numeric(share_womenc),
         Country = if_else(Country == "Germany (Federal Republic Of)", "Germany", Country))

# List of countries by continent

startpage <- "https://statisticstimes.com/geography/countries-by-continents.php" # United Nations classification

searchresults<-read_html(startpage)

tables <- html_table(searchresults)
cont <- tables[[3]] %>% 
  rename(Country = "Country or Area",
         region1 = "Region 1",
         region2 = "Region 2")

## join IPU and continent list

ipuc <- left_join(ipu, cont, by = "Country")

ipuc_eur <- filter(ipuc, Continent == "Europe") %>% 
  mutate(region1 = fct_rev(region1))

# Plot by continent since 1980

world <- filter(ipuc, Year >= 1980) %>% 
  ggplot(aes(Year, share_women, color = Continent)) +
  geom_point(alpha = 0.2) +
  geom_smooth(alpha = 0.2, linetype = 0)+
  stat_smooth(aes(label = Continent),
              geom = "textpath",
              hjust = 0.45) +
  scale_color_viridis(option = "viridis", discrete = TRUE, 
                      na.translate = F, name = NULL) +
  coord_cartesian(ylim = c(0, 0.5), xlim = c(1980, 2020))+
  labs(x = NULL, y = "Share of women MPs",
       subtitle = "Continents compared"
       )

# Plot by region in Europe since 1980

eur <- filter(ipuc_eur, Year >= 1980) %>% 
  ggplot(aes(Year, share_women, color = region1)) +
  geom_point(alpha = 0.2)+
  geom_smooth(alpha = 0.2, linetype = 0)+
  stat_smooth(aes(label = region1),
              geom = "textpath",
              hjust = 0.4) +
  scale_color_viridis(option = "viridis", discrete = TRUE, 
                      name = NULL) +
  coord_cartesian(ylim = c(0, 0.5), xlim = c(1980, 2020))+
  labs(x = NULL, y = "Share of women MPs", 
       subtitle = "Within Europe"
       )

# combine plots
plots_rep <- arrangeGrob(world, eur, 
                         nrow = 2, heights = unit(c(9,9), c("cm"))
)

grid.arrange(plots_rep)


ggsave("figure_a1.pdf", path = figures_path, plot = plots_rep,
       width = 18, height = 18, units = "cm")

```

## Appendix B

### Figure B1

```{r, fig.height = 3.5}
model1 <- lm_robust(soc_pess ~ treatment, data = df_mf)
model3 <- lm_robust(soc_pess ~ treatment * gender, data = df_mf)

plotcate(model3, terms = c("treatment", "gender"), cilvl = 0.834, 
        scaleyname = "Societal pessimism (7 - wrong dir.)")

ggsave(file = "figure_b1.pdf", path = figures_path,
       width = 15, height = 8, units = "cm")

```

### Table B1

```{r}

# Names of coefficients for modelsummary
cm <- c("(Intercept)" = "(Intercept)",
        "treatmentstagnation" = "T1 (Stagnation)",
        "treatmentchange" = "T2 (Change)",
        "genderWomen" = "Women",
        "treatmentstagnation:genderWomen" = "T1 (Stagnation) x Women",
        "treatmentchange:genderWomen" = "T2 (Change) x Women"
)

modelsc <- list("Societal pessimism 1" = model1,
                "Societal pessimism 2" = model3
)
modelsummary(modelsc, coef_map = cm,
             statistic = "p.value",
             conf_level = 0.95,
             stars = T,
             notes = "P-values in parentheses. T1/T2 refers to treatment group assignment.",
             gof_map = c("nobs", "r.squared", "adj.r.squared")
             #output = "latex"
             )

```

## Appendix C

### Table C1

Sample descriptives

```{r}

sample <- df %>%
  select(`Gender` = gender, 
         `Income` = income_group_eq, 
         `Education` = edu, 
         `Age` = age_group, 
         `Migration background` = migrationb, 
         `Residence` = urban,
         `Treatment` = treatment)


datasummary(`Gender` + `Income` + `Education` + `Age` + `Migration background` + `Residence` 
            + `Treatment` + 1 ~ N + Percent(), 
            data = sample, type = "categorical", fmt = 1,
            notes = c("Quota sampling according to German population characteristics (age, gender, education, and federate", 
                          "state) was implemented. Target population includes both citizens and non-citizens.",
                          "Income: equivalized according to household size.", "Migration background: respondent or at least one parent born abroad.", 
                           "Residence: selfreported degree of urbanity/rurality"
                           )
            #output = "latex"
            )

```


### Table C2

Covariate balance

```{r}

datasummary_balance(~Treatment,
                    data = sample,
                    notes = rev(c("Income: equivalized according to household size.", 
                                  "Migration background: respondent or at least one parent born abroad.", 
                              "Residence: selfreported degree of urbanity/rurality"))
                    #output = "latex"
                    )

```

### Table C3

Manipulation check

```{r}

# Two treatment groups, combine manipulation check variables into one
df_treat <- df_mf %>% 
  filter(treatment != "control") %>% 
  mutate(mcheck = if_else(is.na(check_change), check_stable, check_change))

# Total sample
df_treat %>% 
  group_by(treatment) %>% 
  summarise(`Mean Estimate` = mean(mcheck, na.rm = T)) %>% 
  kableExtra::kable(digits = 1) %>% kable_styling()

  # summarise(estimate2050_1 = mean(check_change, na.rm = T),
  #           estimate2050_2 = mean(check_stable, na.rm = T))

# by gender
df_treat %>% 
  group_by(treatment, gender) %>% 
  summarise(`Mean Estimate` = mean(mcheck, na.rm = T))%>% 
  kableExtra::kable(digits = 1) %>% kable_styling(full_width = F)


```

### Table C4

```{r}
t.test(df$check_stable, df$check_change) %>% tidy() %>% 
  select(estimate:conf.high) %>% 
  mutate(across(where(is.numeric), ~as.character(signif(., 3)))) %>% 
  kbl(col.names = c("Difference", "Mean T1", "Mean T2", "t", "p", "df", "Conf. low", "Conf. high"),
    #format = "latex", 
    booktabs = T, linesep = "") %>% 
  kable_styling(latex_options = "scale_down", full_width = F)
```


### Figure C1

```{r, fig.height = 4}
ggplot(data = df_treat, aes(mcheck, linetype = treatment)) + 
  geom_density(bw = 2) +
  geom_vline(aes(xintercept = 49.6), linetype = "dotted") +
  geom_vline(aes(xintercept = 44.4)) +
  labs(x = "Estimate of women's rep. in 2050", y = "Density")

ggsave(file = "figure_c1.pdf", path = figures_path,
       width = 15, height = 8, units = "cm")
```


### Figure C2

Manipulation check by gender

```{r, fig.height = 7}

ggplot(data = df_treat, aes(mcheck, linetype = treatment)) + 
  facet_wrap(~gender, nrow = 2)+
  geom_density(bw = 2) +
  geom_vline(data = filter(df_treat, gender == "Men"), aes(xintercept = 44.2), linetype = "solid") +
  geom_vline(data = filter(df_treat, gender == "Men"), aes(xintercept = 49.5), linetype = "dotted") +
  geom_vline(data = filter(df_treat, gender == "Women"), aes(xintercept = 44.6), linetype = "solid") +
  geom_vline(data = filter(df_treat, gender == "Women"), aes(xintercept = 49.7), linetype = "dotted") +
  labs(x = "Estimate of women's rep. in 2050", y = "Density")

ggsave(file = "figure_c2.pdf", path = figures_path,
       width = 15, height = 15, units = "cm")
```

## Appendix D

### Table D1

```{r}

# Names of coefficients for modelsummary
cm <- c("(Intercept)" = "(Intercept)",
        "treatmentstagnation" = "T1 (Stagnation)",
        "treatmentchange" = "T2 (Change)",
        "genderWomen" = "Women",
        "treatmentstagnation:genderWomen" = "T1 (Stagnation) x Women",
        "treatmentchange:genderWomen" = "T2 (Change) x Women"
)

modelsc <- list("SSS 1" = model4a,
                "SSS 2" = model6a,
                "SSS trajectory 1" = model4b,
                "SSS trajectory 2" = model6b,
                "Pol. centrality 1" = model7,
                "Pol. centrality 2" = model9
)


modelsummary(modelsc, coef_map = cm,
             statistic = "p.value",
             conf_level = 0.95,
             stars = T,
             gof_map = c("nobs", "r.squared", "adj.r.squared"),
             notes = "P-values in parentheses. T1/T2 refers to treatment group assignment.",
             #output = "latex"
             )

```

### Table D2

```{r}

# Linke, SPD
model15 <- lm_robust(ptv_linke ~ treatment * gender, data = df_mf)
model17 <- lm_robust(ptv_spd ~ treatment * gender, data = df_mf)

models <- list("PtV AfD" = model11,
               "PtV Greens" = model13,
               "PtV SPD" = model17,
               "PtV Linke" = model15
)


modelsummary(models, coef_map = cm,
             statistic = "p.value",
             conf_level = 0.95,
             stars = T,
             gof_map = c("nobs", "r.squared", "adj.r.squared"),
             notes = "P-values in parentheses. T1/T2 refers to treatment group assignment.",
             #output = "latex"
             )
```

### Table D3

```{r}

# New reference category: stagnation condition

df_mf <- df_mf %>% 
  mutate(
    treatmentr = fct_relevel(treatment, c("stagnation", "change", "control")) 
  )

ms5n <- lm_robust(boyssupport ~ treatmentr * gender, data = df_mf)

cm <- c("(Intercept)" = "(Intercept)",
        "treatmentrcontrol" = "T0 (Control)",
        "treatmentrchange" = "T2 (Change)",
        "genderWomen" = "Women",
        "treatmentrcontrol:genderWomen" = "T0 (Control) x women",
        "treatmentrchange:genderWomen" = "T2 (Change) x women"
)

models <- list(
  "Support for boys" = ms5n
)



modelsummary(models, coef_map = cm,
             statistic = "p.value",
             conf_level = 0.95,
             stars = T,
             gof_map = c("nobs", "r.squared", "adj.r.squared"),
             notes = rev(c("P-values in parentheses", 
                           "Reference category for treatment assignment is the stability condition", 
                           "to highlight difference to change condition")),
             #output = "latex"
             )



```

### Table D4

```{r}
cm <- c("(Intercept)" = "(Intercept)",
        "treatmentstagnation" = "T1 (Stagnation)",
        "treatmentchange" = "T2 (Change)",
        "genderWomen" = "Women",
        "fem_group2feminist attitude" = "Feminist attitude",
        "treatmentstagnation:genderWomen" = "T1 (Stagnation) x women",
        "treatmentchange:genderWomen" = "T2 (Change) x women",
        "treatmentstagnation:fem_group2feminist attitude" = "T1 x feminist attitude",
        "treatmentchange:fem_group2feminist attitude" = "T2 x feminist attitude",
        "treatmentstagnation:genderWomen:fem_group2feminist attitude" = "T1 x women x feminist attitude",
        "treatmentchange:genderWomen:fem_group2feminist attitude" = "T2 x women x feminist attitude"
)

modelsc <- list("PtV Greens" = model_f13a,
                "PtV Greens" = model_fg13a
)

modelsummary(modelsc, coef_map = cm,
             statistic = "p.value",
             conf_level = 0.95,
             stars = T,
             gof_map = c("nobs", "r.squared", "adj.r.squared"),
             notes = "P-values in parentheses. T1/T2 refers to treatment group assignment.",
             #output = "latex"
             )

```

### Table D5

```{r}
## men control vs. change-------

df_men_cc <- df_mf %>% 
  filter(gender == "Men" & treatment != "stagnation")

### Pol. dep.

ttmpd <- tidy(t.test(pol_depr_mean ~ treatment, data = df_men_cc)) %>% 
  mutate(dv = "Pol. dep.")

### SSS

ttmsss <- tidy(t.test(sssn ~ treatment, data = df_men_cc)) %>% 
  mutate(dv = "SSS")

### SSS trajectory

ttmssst <- tidy(t.test(sss_develop ~ treatment, data = df_men_cc)) %>% 
  mutate(dv = "SSS traj.")

### Support for boys

ttmsb <- tidy(t.test(boyssupport ~ treatment, data = df_men_cc)) %>% 
  mutate(dv = "Supp. boys")

### PtV Afd

ttmafd <- tidy(t.test(ptv_afd ~ treatment, data = df_men_cc)) %>% 
  mutate(dv = "PtV AfD")

### PtV Green

ttmgr <- tidy(t.test(ptv_gruene ~ treatment, data = df_men_cc)) %>% 
  mutate(dv = "PtV Green")

### combine
bind_rows(ttmpd, ttmsss, ttmssst, ttmsb, ttmafd, ttmgr) %>% 
  select(dv, estimate:conf.high) %>% 
  mutate(across(where(is.numeric), ~as.character(signif(., 3)))) %>% 
  kbl(col.names = c("DV","Diff.", "Mean control", "Mean change", "t", "p", "df", "Conf. low", "Conf. high"),
      #format = "latex", 
      booktabs = T, linesep = "",
      caption = "Men: T-tests for differences between control and change conditions"
  ) %>% 
  kable_styling(latex_options = "scale_down")
```


### Table D6

```{r}
## men control vs. stagnation--------

df_men_cs <- df_mf %>% 
  filter(gender == "Men" & treatment != "change")

### Pol. dep.

ttmpd <- tidy(t.test(pol_depr_mean ~ treatment, data = df_men_cs)) %>% 
  mutate(dv = "Pol. dep.")

### SSS

ttmsss <- tidy(t.test(sssn ~ treatment, data = df_men_cs)) %>% 
  mutate(dv = "SSS")

### SSS trajectory

ttmssst <- tidy(t.test(sss_develop ~ treatment, data = df_men_cs)) %>% 
  mutate(dv = "SSS traj.")


### Support for boys

ttmsb <- tidy(t.test(boyssupport ~ treatment, data = df_men_cs)) %>% 
  mutate(dv = "Supp. boys")

### PtV Afd

ttmafd <- tidy(t.test(ptv_afd ~ treatment, data = df_men_cs)) %>% 
  mutate(dv = "PtV AfD")

### PtV Green

ttmgr <- tidy(t.test(ptv_gruene ~ treatment, data = df_men_cs)) %>% 
  mutate(dv = "PtV Green")

### combine
bind_rows(ttmpd, ttmsss, ttmssst, ttmsb, ttmafd, ttmgr) %>% 
  select(dv, estimate:conf.high) %>% 
  mutate(across(where(is.numeric), ~as.character(signif(., 3)))) %>% 
  kbl(col.names = c("DV","Diff.", "Mean control", "Mean stagnation", "t", "p", "df", "Conf. low", "Conf. high"),
      #format = "latex", 
      booktabs = T, linesep = "",
      caption = "Men: T-tests for differences between control and stagnation conditions"
  ) %>% 
  kable_styling(latex_options = "scale_down")
```


### Table D7

```{r}
## men stagnation vs. change--------

df_men_chs <- df_mf %>% 
  filter(gender == "Men" & treatment != "control")

### Pol. dep.

ttmpd <- tidy(t.test(pol_depr_mean ~ treatment, data = df_men_chs)) %>% 
  mutate(dv = "Pol. dep.")

### SSS

ttmsss <- tidy(t.test(sssn ~ treatment, data = df_men_chs)) %>% 
  mutate(dv = "SSS")

### SSS trajectory

ttmssst <- tidy(t.test(sss_develop ~ treatment, data = df_men_chs)) %>% 
  mutate(dv = "SSS traj.")

### Support for boys

ttmsb <- tidy(t.test(boyssupport ~ treatment, data = df_men_chs)) %>% 
  mutate(dv = "Supp. boys")

### PtV Afd

ttmafd <- tidy(t.test(ptv_afd ~ treatment, data = df_men_chs)) %>% 
  mutate(dv = "PtV AfD")

### PtV Green

ttmgr <- tidy(t.test(ptv_gruene ~ treatment, data = df_men_chs)) %>% 
  mutate(dv = "PtV Green")

### combine
bind_rows(ttmpd, ttmsss, ttmssst, ttmsb, ttmafd, ttmgr) %>% 
  select(dv, estimate:conf.high) %>% 
  mutate(across(where(is.numeric), ~as.character(signif(., 3)))) %>% 
  kbl(col.names = c("DV","Diff.", "Mean stagnation", "Mean change", "t", "p", "df", "Conf. low", "Conf. high"),
      #format = "latex", 
      booktabs = T, linesep = "",
      caption = "Men: T-tests for differences between stagnation and change conditions"
  ) %>% 
  kable_styling(latex_options = "scale_down")
```


### Table D8

```{r}

## women control vs. change-----

df_women_cc <- df_mf %>% 
  filter(gender == "Women" & treatment != "stagnation")

### Pol. dep.

ttwpd <- tidy(t.test(pol_depr_mean ~ treatment, data = df_women_cc)) %>% 
  mutate(dv = "Pol. dep.")

### SSS

ttwsss <- tidy(t.test(sssn ~ treatment, data = df_women_cc)) %>% 
  mutate(dv = "SSS")

### SSS trajectory

ttwssst <- tidy(t.test(sss_develop ~ treatment, data = df_women_cc)) %>% 
  mutate(dv = "SSS traj.")

### Support for boys

ttwsb <- tidy(t.test(boyssupport ~ treatment, data = df_women_cc)) %>% 
  mutate(dv = "Supp. boys")

### PtV Afd

ttwafd <- tidy(t.test(ptv_afd ~ treatment, data = df_women_cc)) %>% 
  mutate(dv = "PtV AfD")

### PtV Green

ttwgr <- tidy(t.test(ptv_gruene ~ treatment, data = df_women_cc)) %>% 
  mutate(dv = "PtV Green")

### combine
bind_rows(ttwpd, ttwsss, ttwssst, ttwsb, ttwafd, ttwgr) %>% 
  select(dv, estimate:conf.high) %>% 
  mutate(across(where(is.numeric), ~as.character(signif(., 3)))) %>% 
  kbl(col.names = c("DV","Diff.", "Mean control", "Mean change", "t", "p", "df", "Conf. low", "Conf. high"),
      #format = "latex", 
      booktabs = T, linesep = "",
      caption = "Women: T-tests for differences between control and change conditions"
  ) %>% 
  kable_styling(latex_options = "scale_down")

```


### Table D9

```{r}
## women control vs. stagnation-----

df_women_cs <- df_mf %>% 
  filter(gender == "Women" & treatment != "change")

### Pol. dep.

ttwpd <- tidy(t.test(pol_depr_mean ~ treatment, data = df_women_cs)) %>% 
  mutate(dv = "Pol. dep.")

### SSS

ttwsss <- tidy(t.test(sssn ~ treatment, data = df_women_cs)) %>% 
  mutate(dv = "SSS")

### SSS trajectory

ttwssst <- tidy(t.test(sss_develop ~ treatment, data = df_women_cs)) %>% 
  mutate(dv = "SSS traj.")

### Support for boys

ttwsb <- tidy(t.test(boyssupport ~ treatment, data = df_women_cs)) %>% 
  mutate(dv = "Supp. boys")

### PtV Afd

ttwafd <- tidy(t.test(ptv_afd ~ treatment, data = df_women_cs)) %>% 
  mutate(dv = "PtV AfD")

### PtV Green

ttwgr <- tidy(t.test(ptv_gruene ~ treatment, data = df_women_cs)) %>% 
  mutate(dv = "PtV Green")

### combine
bind_rows(ttwpd, ttwsss, ttwssst, ttwsb, ttwafd, ttwgr) %>% 
  select(dv, estimate:conf.high) %>% 
  mutate(across(where(is.numeric), ~as.character(signif(., 3)))) %>% 
  kbl(col.names = c("DV","Diff.", "Mean control", "Mean stagnation", "t", "p", "df", "Conf. low", "Conf. high"),
      #format = "latex", 
      booktabs = T, linesep = "",
      caption = "Women: T-tests for differences between control and stagnation conditions"
  ) %>% 
  kable_styling(latex_options = "scale_down")
```

### Table D10

```{r}
## women stagnation vs. change-----

df_women_chs <- df_mf %>% 
  filter(gender == "Women" & treatment != "control")

### Pol. dep.

ttwpd <- tidy(t.test(pol_depr_mean ~ treatment, data = df_women_chs)) %>% 
  mutate(dv = "Pol. dep.")

### SSS

ttwsss <- tidy(t.test(sssn ~ treatment, data = df_women_chs)) %>% 
  mutate(dv = "SSS")

### SSS trajectory

ttwssst <- tidy(t.test(sss_develop ~ treatment, data = df_women_chs)) %>% 
  mutate(dv = "SSS traj.")


### Support for boys

ttwsb <- tidy(t.test(boyssupport ~ treatment, data = df_women_chs)) %>% 
  mutate(dv = "Supp. boys")

### PtV Afd

ttwafd <- tidy(t.test(ptv_afd ~ treatment, data = df_women_chs)) %>% 
  mutate(dv = "PtV AfD")

### PtV Green

ttwgr <- tidy(t.test(ptv_gruene ~ treatment, data = df_women_chs)) %>% 
  mutate(dv = "PtV Green")

### combine
bind_rows(ttwpd, ttwsss, ttwssst, ttwsb, ttwafd, ttwgr) %>% 
  select(dv, estimate:conf.high) %>% 
  mutate(across(where(is.numeric), ~as.character(signif(., 3)))) %>% 
  kbl(col.names = c("DV","Diff.", "Mean stagnation", "Mean change", "t", "p", "df", "Conf. low", "Conf. high"),
      #format = "latex", 
      booktabs = T, linesep = "",
      caption = "Women: T-tests for differences between stagnation and change conditions"
  ) %>% 
  kable_styling(latex_options = "scale_down")
```

### Table D11

```{r}
# significance of difference between genders-----

## control

df_control <- df_mf %>% 
  filter(treatment == "control")


### Pol. dep.

ttpd <- tidy(t.test(pol_depr_mean ~ gender, data = df_control)) %>% 
  mutate(dv = "Pol. dep.")

### SSS

ttsss <- tidy(t.test(sssn ~ gender, data = df_control)) %>% 
  mutate(dv = "SSS")

### SSS trajectory

ttssst <- tidy(t.test(sss_develop ~ gender, data = df_control)) %>% 
  mutate(dv = "SSS traj.")


### Support for boys

ttsb <- tidy(t.test(boyssupport ~ gender, data = df_control)) %>% 
  mutate(dv = "Supp. boys")

### PtV Afd

ttafd <- tidy(t.test(ptv_afd ~ gender, data = df_control)) %>% 
  mutate(dv = "PtV AfD")

### PtV Green

ttgr <- tidy(t.test(ptv_gruene ~ gender, data = df_control)) %>% 
  mutate(dv = "PtV Green")

### combine
bind_rows(ttpd, ttsss, ttssst, ttsb, ttafd, ttgr) %>% 
  select(dv, estimate:conf.high) %>% 
  mutate(across(where(is.numeric), ~as.character(signif(., 3)))) %>% 
  kbl(col.names = c("DV","Diff.", "Mean men", "Mean women", "t", "p", "df", "Conf. low", "Conf. high"),
      #format = "latex", 
      booktabs = T, linesep = "",
      caption = "Control condition: T-tests for differences between men and women"
  ) %>% 
  kable_styling(latex_options = "scale_down")
```


### Table D12

```{r}
## stagnation

df_stable <- df_mf %>% 
  filter(treatment == "stagnation")

### Pol. dep.

ttpd <- tidy(t.test(pol_depr_mean ~ gender, data = df_stable)) %>% 
  mutate(dv = "Pol. dep.")

### SSS

ttsss <- tidy(t.test(sssn ~ gender, data = df_stable)) %>% 
  mutate(dv = "SSS")

### SSS trajectory

ttssst <- tidy(t.test(sss_develop ~ gender, data = df_stable)) %>% 
  mutate(dv = "SSS traj.")

### Support for boys

ttsb <- tidy(t.test(boyssupport ~ gender, data = df_stable)) %>% 
  mutate(dv = "Supp. boys")

### PtV Afd

ttafd <- tidy(t.test(ptv_afd ~ gender, data = df_stable)) %>% 
  mutate(dv = "PtV AfD")

### PtV Green

ttgr <- tidy(t.test(ptv_gruene ~ gender, data = df_stable)) %>% 
  mutate(dv = "PtV Green")

### combine
bind_rows(ttpd, ttsss, ttssst, ttsb, ttafd, ttgr) %>% 
  select(dv, estimate:conf.high) %>% 
  mutate(across(where(is.numeric), ~as.character(signif(., 3)))) %>% 
  kbl(col.names = c("DV","Diff.", "Mean men", "Mean women", "t", "p", "df", "Conf. low", "Conf. high"),
      #format = "latex", 
      booktabs = T, linesep = "",
      caption = "stagnation condition: T-tests for differences between men and women"
  ) %>% 
  kable_styling(latex_options = "scale_down")
```

### Table D13


```{r}

## change

df_change <- df_mf %>% 
  filter(treatment == "change")

### Pol. dep.

ttpd <- tidy(t.test(pol_depr_mean ~ gender, data = df_change)) %>% 
  mutate(dv = "Pol. dep.")

### SSS

ttsss <- tidy(t.test(sssn ~ gender, data = df_change)) %>% 
  mutate(dv = "SSS")

### SSS trajectory

ttssst <- tidy(t.test(sss_develop ~ gender, data = df_change)) %>% 
  mutate(dv = "SSS traj.")


### Support for boys

ttsb <- tidy(t.test(boyssupport ~ gender, data = df_change)) %>% 
  mutate(dv = "Supp. boys")

### PtV Afd

ttafd <- tidy(t.test(ptv_afd ~ gender, data = df_change)) %>% 
  mutate(dv = "PtV AfD")

### PtV Green

ttgr <- tidy(t.test(ptv_gruene ~ gender, data = df_change)) %>% 
  mutate(dv = "PtV Green")

### combine
bind_rows(ttpd, ttsss, ttssst, ttsb, ttafd, ttgr) %>% 
  select(dv, estimate:conf.high) %>% 
  mutate(across(where(is.numeric), ~as.character(signif(., 3)))) %>% 
  kable(col.names = c("DV","Diff.", "Mean men", "Mean women", "t", "p", "df", "Conf. low", "Conf. high"),
      #format = "latex", 
      booktabs = T, linesep = "",
      caption = "Change condition: T-tests for differences between men and women"
  ) %>% 
  kable_styling(latex_options = "scale_down")
```

### Table D14

```{r}
## t-tests for anti-feminist women: stagnation vs both other conditions

### stagnation vs. control

df_women_afcs <- df_mf %>% 
  filter(gender == "Women" & treatment != "change" & fem_group2 == "anti-feminist attitude")

ttafcs <- tidy(t.test(ptv_gruene ~ treatment, data = df_women_afcs)) %>% 
  mutate(dv = "PtV Green")

ttafcs %>% select(dv, estimate:conf.high) %>% 
  mutate(across(where(is.numeric), ~as.character(signif(., 3)))) %>% 
  kbl(col.names = c("DV","Diff.", "Mean control", "Mean stagnation", "t", "p", "df", "Conf. low", "Conf. high"),
      #format = "latex", 
      booktabs = T, linesep = "",
      caption = "Anti-feminist women: T-test for difference between stagnation and control condition"
  ) %>% 
  kable_styling(latex_options = "scale_down")


```

### Table D15

```{r}
### stagnation vs. change
df_women_afchs <- df_mf %>% 
  filter(gender == "Women" & treatment != "control" & fem_group2 == "anti-feminist attitude")

ttafchs <- tidy(t.test(ptv_gruene ~ treatment, data = df_women_afchs)) %>% 
  mutate(dv = "PtV Green")

ttafchs %>% select(dv, estimate:conf.high) %>% 
  mutate(across(where(is.numeric), ~as.character(signif(., 3)))) %>% 
  kbl(col.names = c("DV","Diff.", "Mean stagnation", "Mean change", "t", "p", "df", "Conf. low", "Conf. high"),
      #format = "latex", 
      booktabs = T, linesep = "",
      caption = "Anti-feminist women: T-test for difference between stagnation and change condition"
  ) %>% 
  kable_styling(latex_options = "scale_down")
```


### Figure D1

```{r, fig.height = 7}

model6a95 <- lm_robust(sssn ~ treatment * gender, data = df_mf)

sss95 <- plotcate(model6a95, c("treatment", "gender"), cilvl = 0.95,
                "Present SSS", "Present SSS")


model6b95 <- lm_robust(sss_develop ~ treatment * gender, data = df_mf)

sss_t95 <- plotcate(model6b95, c("treatment", "gender"), cilvl = 0.95, 
                  "SSS trajectory", "SSS trajectory (future minus past SSS)")


# combine plots
plots_sss95 <- arrangeGrob(sss95, sss_t95, 
                         nrow = 2, heights = unit(c(8.5,8.5), c("cm"))
)

grid.arrange(plots_sss95)

ggsave(file = "figure_d1.pdf", path = figures_path, plot = plots_sss95,
       width = 15, height = 17, units = "cm")

```

### Figure D2

```{r, fig.height = 3.5}
model995 <- lm_robust(pol_depr_mean ~ treatment * gender, data = df_mf)

plotcate(model995, c("treatment", "gender"), cilvl = 0.95,
         scaleyname = "Political centrality")

ggsave(file = "figure_d2.pdf", path = figures_path,
       width = 15, height = 8.5, units = "cm")
```

### Figure D3

```{r, fig.height = 7}
model1195 <- lm_robust(ptv_afd ~ treatment * gender, data = df_mf)

pafd95 <- plotcate(model1195, terms = c("treatment", "gender"),
                   cilvl = 0.95,
                   scaleyname = "PtV AfD",
                   subtitle = "Radical Right"
)


model1395 <- lm_robust(ptv_gruene ~ treatment * gender, data = df_mf)

pgru95 <- plotcate(model1395, terms = c("treatment", "gender"),
                   cilvl = 0.95,
                   scaleyname = "PtV Greens",
                   subtitle = "Greens"
)


# combine plots
plots_ptv95 <- arrangeGrob(pafd95, pgru95, 
                         nrow = 2, heights = unit(c(8.5, 8.5), c("cm"))
)

grid.arrange(plots_ptv95)

ggsave(file = "figure_d3.pdf", path = figures_path, plot = plots_ptv95,
       width = 15, height = 17, units = "cm")
```

### Figure D4

```{r, fig.height = 3.5}
ms595 <- lm_robust(boyssupport ~ treatment * gender, data = df_mf)

plotcate(ms595, c("treatment", "gender"), 
         cilvl = 0.95,
         scaleyname = "Primarily support for boys needed")

ggsave(file = "figure_d4.pdf", path = figures_path,
       width = 15, height = 8.5, units = "cm")
```

## Appendix E

### Figure E1

Individual political centrality items

```{r, fig.height = 7}

model9a <- lm_robust(pol_depr_care ~ treatment * gender, data = df_mf)

model9b <- lm_robust(pol_depr_power ~ treatment * gender, data = df_mf)

pd1 <- plotcate(model9a, c("treatment", "gender"), scaleyname = "Agreement (1 to 7)",
                subtitle = "Politicians will care about people like me")

pd2 <- plotcate(model9b, c("treatment", "gender"), scaleyname = "Agreement (1 to 7)",
                subtitle = "People like me will have political power")
  
# combine
plots_pd <- arrangeGrob(pd1, pd2, 
                         nrow = 2, heights = unit(c(8.5,8.5), c("cm"))
)

grid.arrange(plots_pd)

ggsave(file = "figure_e1.pdf", path = figures_path, plot = plots_pd,
       width = 15, height = 17, units = "cm")
```


### Figure E2

```{r, fig.height = 7}

linke <- plotcate(model15, terms = c("treatment", "gender"),
                  scaleyname = "PtV Linke",
                  subtitle = "Radical Left")

# SPD


spd <- plotcate(model17, terms = c("treatment", "gender"),
                scaleyname = "PtV SPD",
                subtitle = "Social Democrats"
                )

# combine SPD and Linke
plots_left <- arrangeGrob(spd, linke, 
                        nrow = 2, heights = unit(c(8.5,8.5), c("cm"))
)

grid.arrange(plots_left)

ggsave(file = "figure_e2.pdf", path = figures_path, plot = plots_left,
       width = 15, height = 17, units = "cm")
```


### Figure E3

```{r, fig.height = 7}
model19 <- lm_robust(ptv_cducsu ~ treatment * gender, data = df_mf)
model21 <- lm_robust(ptv_fdp ~ treatment * gender, data = df_mf)

cdu <- plotcate(model19, terms = c("treatment", "gender"),
         scaleyname = "PtV CDU/CSU")

fdp <- plotcate(model21, terms = c("treatment", "gender"),
         scaleyname = "PtV FDP")

# combine
plots_right <- arrangeGrob(cdu, fdp, 
                          nrow = 2, heights = unit(c(8.5,8.5), c("cm"))
)

grid.arrange(plots_right)

ggsave(file = "figure_e3.pdf", path = figures_path, plot = plots_right,
       width = 15, height = 17, units = "cm")
```

### Figure E4

```{r, fig.height = 8}

model_fg6 <- lm_robust(sssn ~ treatment * gender* fem_group2, data = df_mf)

sss<- plotcate3(model_fg6, c("treatment", "fem_group2", "gender"),
          scaleyname = "Present SSS",
          subtitle = "Present SSS")

model_fg6b <- lm_robust(sss_develop ~ treatment * gender* fem_group2, data = df_mf)

sss_t <- plotcate3(model_fg6b, c("treatment","fem_group2", "gender"),
          scaleyname = "SSS trajectory",
          subtitle = "SSS trajectory (future minus past SSS)")

# combine plots
plots_sss <- arrangeGrob(sss, sss_t, 
                         nrow = 2, heights = unit(c(9.5,9.5), c("cm"))
)

grid.arrange(plots_sss)

ggsave(file = "figure_e4.pdf", path = figures_path, plot = plots_sss,
       width = 15, height = 19, units = "cm")

```


### Figure E5

```{r, fig.height = 8}
model_eg6 <- lm_robust(sssn ~ treatment * gender * edu, data = df_mf)

sss <- plotcate3col(model_eg6, c("treatment", "edu", "gender"),
          scaleyname = "Present SSS", subtitle = "Present SSS") 


# SSS development

model_eg6b <- lm_robust(sss_develop ~ treatment * gender* edu, data = df_mf)

sss_t <- plotcate3col(model_eg6b, terms = c("treatment", "edu", "gender"),
          scaleyname = "SSS trajectory",
          subtitle = "SSS trajectory (future minus past SSS)")

# combine plots
plots_sss <- arrangeGrob(sss, sss_t, 
                         nrow = 2, heights = unit(c(9.5,9.5), c("cm"))
)

grid.arrange(plots_sss)

ggsave(file = "figure_e5.pdf", path = figures_path, plot = plots_sss,
       width = 15, height = 18, units = "cm")

```


### Figure E6

```{r, fig.height = 8}
model_ag4 <- lm_robust(sssn ~ treatment * age_group * gender, data = df_mf)

agesss <- plotcate3col(model_ag4, c("treatment", "age_group", "gender"),
         scaleyname = "Present SSS",
         subtitle = "Present SSS")

model_ag5 <- lm_robust(sss_develop ~ treatment * age_group * gender, data = df_mf)

agessst <- plotcate3col(model_ag5, c("treatment", "age_group", "gender"),
             scaleyname = "SSS trajectory",
             subtitle = "SSS trajectory (future minus past SSS)")

# combine plots
plots_agesss <- arrangeGrob(agesss, agessst, 
                         nrow = 2, heights = unit(c(9.5,9.5), c("cm"))
)

grid.arrange(plots_agesss)

ggsave(file = "figure_e6.pdf", path = figures_path, plot = plots_agesss,
       width = 15, height = 19, units = "cm")
```


### Figure E7

```{r, fig.height = 4}
model_fg9a <- lm_robust(pol_depr_mean ~ treatment * gender * fem_group2, data = df_mf)

plotcate3(model_fg9a, c("treatment", "fem_group2", "gender"),
          scaleyname = "Political centrality")

ggsave(file = "figure_e7.pdf", path = figures_path,
       width = 15, height = 9, units = "cm")
```


### Figure E8

```{r, fig.height = 4}
model_eg9 <- lm_robust(pol_depr_mean ~ treatment * edu * gender, data = df_mf)

plotcate3col(model_eg9, c("treatment", "edu", "gender"),
          scaleyname = "Political centrality")

ggsave(file = "figure_e8.pdf", path = figures_path,
       width = 15, height = 9, units = "cm")
```

## Figure E9

```{r, fig.height = 4}
model_sag3 <- lm_robust(pol_depr_mean ~ treatment * gender * age_group , 
                        data = df_mf)

plotcate3col(model_sag3, c("treatment", "age_group", "gender"))

ggsave(file = "figure_e9.pdf", path = figures_path,
       width = 15, height = 9, units = "cm")
```

### Figure E10

```{r, fig.height = 4}
model_fg11 <- lm_robust(ptv_afd ~ treatment * gender * fem_group2, data = df_mf)

plotcate3(model_fg11, c("treatment", "fem_group2", "gender"),
          scaleyname = "PtV AfD")

ggsave(file = "figure_e10.pdf", path = figures_path,
       width = 15, height = 9, units = "cm")
```


### Figure E11

```{r, fig.height = 8}

model_e10g <- lm_robust(ptv_gruene ~ treatment * gender * edu, data = df_mf)

greens <- plotcate3col(model_e10g, c("treatment", "edu", "gender"),
          scaleyname = "PtV Greens",
          subtitle = "Greens")

model_e11g <- lm_robust(ptv_afd ~ treatment * gender * edu, data = df_mf)

afd <- plotcate3col(model_e11g, c("treatment", "edu", "gender"),
             scaleyname = "PtV AfD",
             subtitle = "Radical right")

# combine plots
plots_ptvedu <- arrangeGrob(afd, greens,
                         nrow = 2, heights = unit(c(9.5,9.5), c("cm"))
)

grid.arrange(plots_ptvedu)

ggsave(file = "figure_e11.pdf", path = figures_path, plot = plots_ptvedu,
       width = 15, height = 19, units = "cm")
```


### Figure E12

```{r, fig.height = 8}
model_ag6 <- lm_robust(ptv_afd ~ treatment * age_group * gender, data = df_mf)

afd <- plotcate3col(model_ag6, c("treatment", "age_group", "gender"),
         scaleyname = "PtV AfD",
         subtitle = "Radical right")

model_ag7 <- lm_robust(ptv_gruene ~ treatment * age_group * gender, data = df_mf)

greens <- plotcate3col(model_ag7, c("treatment", "age_group", "gender"),
         scaleyname = "PtV Greens",
         subtitle = "Greens")

# combine plots
plots_ptvage <- arrangeGrob(afd, greens,
                            nrow = 2, heights = unit(c(9.5,9.5), c("cm"))
)

grid.arrange(plots_ptvage)

ggsave(file = "figure_e12.pdf", path = figures_path, plot = plots_ptvage,
       width = 15, height = 19, units = "cm")
```

